
<?
	   layout("/inc/win_layout.html",{title:sysTitle}){
    ?>

<div class="row" style="min-height: auto;padding-bottom: 20px;">
	<div class="panel">
		<div class="col-lg-12">
			<div class="panel-body pan">
				<form action="#" class="form-horizontal">
					<div class="form-body pal" style="width:auto; height: auto;">

						<div style="width:370px;  margin:0 30px 0 60px; padding-bottom: 15px;">
							<label for="inputUsername" class="col-md-3 control-label">中文名称
								<span class='require' id="zhongwenName">*</span> </label>
							<div class="col-md-9">
								<div class="input-icon">
									<input id="nameZh" type="text" class="form-control" onchange="pinYin(this.value)" />
								</div>
							</div>
						</div>


						<div style="width:370px;  margin:0 30px 0 60px; padding-bottom: 15px;">
							<label for="inputUsername" class="col-md-3 control-label">英文名称
								<span class='require' id="yingwenName">*</span> </label>
							<div class="col-md-9">
								<div class="input-icon">
									<input id="nameEn" type="text" class="form-control" />
								</div>
							</div>
						</div>

						<div style="width:370px;  margin:0 30px 0 60px; padding-bottom: 15px;">
							<label for="inputUsername" class="col-md-3 control-label">类型
								<span class='require' id="leixing">*</span> </label>
							<div class="col-md-9">
								<div class="input-icon">
									<select id="dictType" class="form-control">
										<option value="-1">请选择</option>
										<option value="1">普通结构(名称-值)</option>
										<option value="2">树形结构</option>
									</select>
								</div>
							</div>
						</div>
						
						<div style="width:370px;  margin:0 30px 0 60px; padding-bottom: 15px;">
							<label for="inputUsername" class="col-md-3 control-label">排序
								<span class='require' id="paixu">*</span> </label>
							<div class="col-md-9">
								<div class="input-icon">
									<input id="sort" type="text" class="form-control" />
								</div>
							</div>
						</div>
						<input id="id" type="hidden" class="form-control" />
						
					</div>	
				</form>
			</div>
		</div>
	</div>
</div>

<?} ?>
<script>
	var index1 = window.parent.getlay();
	var sum = window.parent.getsum();
	var curr = window.parent.getCurr();
	$(function() {
		if (index1 != 0) {
			$("#id").val(index1);
			demo1();
		}else{
			$("#sort").val(sum);
		}
	});
	function Page() {
				if($.trim($("#nameZh").val()).length<1) {
    	        	alert('中文名称不能为空！');
    	        	return null;
    	        }
				if($.trim($("#nameEn").val()).length<1) {
    	        	alert('英文名称不能为空！');
    	        	return null;
    	        }
    	        if($.trim($("#dictType").val())=="-1") {
    	        	alert('请选择数据类型！');
    	        	return null;
    	        }
    	        if($.trim($("#sort").val()).length<1) {
    	        	alert('排序不能为空！');
    	        	return null;
    	        }
    	        if(isNaN($("#sort").val())){
                  alert("必须是数字");
                  return null;
                   }
	
		$.ajax({
			type : "post",
			url : "./dictAddandUpdate.do",
			data : {
				"id" : index1,
				"nameZh" : $("#nameZh").val(),
				"nameEn" : $("#nameEn").val(),
				"dictType" : $("#dictType").val(),
				"sort": $("#sort").val(),
			},
			dataType : "json",
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.get();
				window.parent.demo1(curr);
				parent.layer.msg('提交成功');
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}

	function demo1() {
		$.getJSON('./dictfindone.do', {
			id : index1
		//向服务端传的参数，此处只是演示
		}, function(res) {
			//此处仅仅是为了演示变化的内容
			$("#nameZh").val(res[0].nameZh);
			$("#nameEn").val(res[0].nameEn);
			$("#dictType").val(res[0].dictType);
			$("#sort").val(res[0].sort);
		});
	};

//汉字转拼音
  function pinYin(pinyinName){
		$.ajax({
			type : "post",
			url : "pinYin.do",
			data : {
				"pinYin" : pinyinName,
			},
			async : false,
			dataType : "json",
			success : function(data) {
				if(data[0].length > 32){
					layer.msg('自动转换英文名长度过长!请手动输入！');
					$("#nameEn").val("");
				}else{
					$("#nameEn").val(data);
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		})
		}


</script>


